<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
<script>
//cancat
var arr1 = [1,2,3,4]
var arr2 = [5,6,7,8]
console.log(arr1.concat(arr2))
console.log(arr1.concat(100))

var arr3 = [1,2,3,4,2]
console.log(arr3.join('&'))

console.log(arr3.toString())

//indexof lastindexof
console.log(arr3.indexOf(2))
console.log(arr3.lastIndexOf(2))

var arr4 = [11,22,333,44,5,66]
console.log(arr4.includes(44))
//判断一个数组是否含有某一个元素的方法
//1.indexof || lastindexof
var arr5 = [100,200,300,400]
console.log(arr5.indexOf(500))
//2.includes
console.log(arr5.includes(400))

//flat
//一维数组
var arr6 = [1,2,3,4,5,6]

//二维数组
var arr7 = [1,2,[3,4]]
console.log(arr7.flat(2))
//多维度数组
var arr8 = [1,2,3,[4,5,[6,7,[8,9,0]]]]
console.log(arr8.flat(Infinity))

//foreach
var arr10 =[100,200,300,400,500,600]
arr10.forEach(function(item,index) {
    console.log(item,index)
})
var arr11 = [[1,2],[3,4],[5,6],[7,8]]
arr11.forEach(function(item) {
    item.forEach(function (item1){
        console.log(item1)
    })
})

for (var i = 0;i<arr11.length;i++){
    for(var j =0 ;j<arr11[i];j++){
        console.log(arr11[i][j])
    }
}
//some 数组中是否存在某一些值满足某一个条件
var arr12 =[100,200,300,400,500]
console.log(arr12.some(function (item,index){
console.log(item)
return item > 300
}))
//every 数组中是否存在某一些值满足某一个条件
console.log(
    arr12.every(function(item,index){
        console.log(item)
        return item >9
    })
)

//some every区别
//some只要有一个元素满足条件就返回true，而every则需要所有元素都满足条件才
//some只要找到满足条件的值就会返回，every会把所有的元素都判断一遍
//filter 有一个筛选的条件
console.log(
    arr12.filter(function(item,index){
        return item % 2 == 0
    })
)
//map 用于改变数组中的元素
console.log(
    arr12.map(function(item,index){
        return item / 2
    })
)


//reduce 累加器
 var arr13 = [100,200,300,400]
 console.log(arr13.reduce(function(pre,item,index){
    console.log(pre,item,index)
    return pre+item
 },0)
)
var arr14 =['a','b','c','d','e']  //abcde字符串
console.log(
    arr14.reduce(function(pre,item,index){
        console.log(pre,item,index)
        return  pre+item
    },'')
)
</script>
</body>
</html>